package com.hengxinguotong.zhihuichengjian.ui.lift.data;

import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.LiftHistory;
import com.hengxinguotong.zhihuichengjian.ui.BaseActivity;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/24
 *
 * 升降机历史数据详情
 */

public class LiftHistoryDetailActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.title_tv)
    HXTextView titleTv;
    @BindView(R.id.upload_time)
    HXTextView uploadTime;
    @BindView(R.id.load)
    HXTextView load;
    @BindView(R.id.load_percent)
    HXTextView loadPercent;
    @BindView(R.id.person_count)
    HXTextView personCount;
    @BindView(R.id.height)
    HXTextView height;
    @BindView(R.id.height_percent)
    HXTextView heightPercent;
    @BindView(R.id.speed)
    HXTextView speed;
    @BindView(R.id.direction)
    HXTextView direction;
    @BindView(R.id.x_tilt_angle)
    HXTextView xTiltAngle;
    @BindView(R.id.y_tilt_angle)
    HXTextView yTiltAngle;
    @BindView(R.id.x_tilt_percent)
    HXTextView xTiltPercent;
    @BindView(R.id.y_tilt_percent)
    HXTextView yTiltPercent;
    @BindView(R.id.before_door_status)
    HXTextView beforeDoorStatus;
    @BindView(R.id.behind_door_status)
    HXTextView behindDoorStatus;

    private LiftHistory liftHistory;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lift_history_detail);
        ButterKnife.bind(this);
        liftHistory = (LiftHistory) getIntent().getSerializableExtra("liftHistory");
        initView();
    }

    private void initView() {
        titleTv.setText(R.string.history_data_detail);

        uploadTime.setText(liftHistory.getAcquisitionTime());
        setmText(load, liftHistory.getWeight() + "千克", liftHistory.getSystemStatusWeight());//	系统状态-重量 : 0-正常，1-预警，2-报警
        setmText(loadPercent, liftHistory.getWeightPercent() + "%", liftHistory.getSystemStatusWeight());//	系统状态-重量 : 0-正常，1-预警，2-报警
        setmText(personCount, liftHistory.getPeopleNum() + "人", liftHistory.getSystemStatusNum());//系统状态-人数 : 0-正常，1-预警，2-报警
        setmText(height, liftHistory.getHeight() + "米", liftHistory.getSystemStatusHeight());//	系统状态-高度限位 : 0-正常，1-预警，2-报警
        setmText(heightPercent, liftHistory.getHeightPercent() + "%", liftHistory.getSystemStatusHeight());//系统状态-高度限位 : 0-正常，1-预警，2-报警
        setmText(speed, liftHistory.getSpeed() + "米/秒", liftHistory.getSystemStatusSpeed());//系统状态-超速 : 0-正常，1-预警，2-报警
        switch (liftHistory.getSpeedStatus()){//实时速度--方向 0：停止；1：上 2：下
            case 0:
                direction.setText("停止");
                break;
            case 1:
                direction.setText("上");
                break;
            case 2:
                direction.setText("下");
                break;
        }
        setmText(xTiltAngle, "（X）" + liftHistory.getObliquity() + "度", liftHistory.getSystemStatusTilt());//系统状态-倾斜 : 0-正常，1-预警，2-报警
        setmText(xTiltPercent, "（X）" + liftHistory.getObliquityPercent() + "%", liftHistory.getSystemStatusTilt());//系统状态-倾斜 : 0-正常，1-预警，2-报警
        setmText(yTiltAngle, "（Y）" + liftHistory.getTilt() + "度", liftHistory.getSystemStatusTilt());//系统状态-倾斜 : 0-正常，1-预警，2-报警
        setmText(yTiltPercent, "（Y）" + liftHistory.getTiltPercent() + "%", liftHistory.getSystemStatusTilt());//系统状态-倾斜 : 0-正常，1-预警，2-报警
        setDoorText(beforeDoorStatus, getDoorStatus("（前门）", liftHistory.getForeDoorStatus()), liftHistory.getSystemStatusForeLockStatus());//系统状态-前门锁状态 : 0-正常,1-异常
        setDoorText(behindDoorStatus, getDoorStatus("（后门）", liftHistory.getBehindDoorStatus()), liftHistory.getSystemStatusBehindLockStatus());//系统状态-前门锁状态 : 0-正常,1-异常
    }

    @OnClick({R.id.back_tv})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back_tv:
                finish();
                break;
        }
    }

    private void setmText(HXTextView textView, String text, int status){
        switch (status){
            case 0:
                textView.setText(text);
                textView.setTextColor(getmColor(R.color.color_666666));
                break;
            case 1:
                textView.setText(text + "（预警）");
                textView.setTextColor(getmColor(R.color.color_FD9D00));
                break;
            case 2:
                textView.setText(text + "（报警）");
                textView.setTextColor(getmColor(R.color.color_F5573F));
                break;
        }
    }

    private void setDoorText(HXTextView textView, String text, int status){
        switch (status){//系统状态-前/后门锁状态 : 0-正常,1-异常
            case 0:
                textView.setText(text);
                textView.setTextColor(getmColor(R.color.color_666666));
                break;
            case 1:
                textView.setText(text + "（异常）");
                textView.setTextColor(getmColor(R.color.color_F5573F));
                break;
        }
    }

    private String getDoorStatus(String text, int doorStatus){//前/后门状态 1-开启，0-关闭
        switch (doorStatus){
            case 0:
                text = text + "关闭";
                break;
            case 1:
                text = text + "开启";
                break;
        }
        return  text;
    }

    private int getmColor(int colorId){
        return getResources().getColor(colorId);
    }
}
